package com.wdcg.model.access;

import java.sql.SQLException;
import java.util.Locale;

import android.util.Log;

import com.j256.ormlite.stmt.QueryBuilder;
import com.wdcg.model.dao.PlayerLocale;
import com.wdcg.model.dbhelper.DatabaseHelper;

public class LocaleAccess {
 public static PlayerLocale getCurrUserLocale(){
	 DatabaseHelper dbh=DatabaseHelper.getMainDBHelper();
	 QueryBuilder<PlayerLocale, Integer> languageQB = dbh.getPlayereLocaleDao().queryBuilder();
		String lang = Locale.getDefault().getLanguage();
		PlayerLocale userLang=null;
		try {
			languageQB.where().eq(PlayerLocale.LOCALE_NAME_COLUMN, lang);
			userLang = languageQB.queryForFirst();
			if (userLang == null) {
				languageQB.where().eq(PlayerLocale.LOCALE_NAME_COLUMN, "en");
				userLang = languageQB.queryForFirst();
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return userLang;
 }
}
